<?php

/**
 * Created by PhpStorm
 * User: 林振宇
 * Date: 2020/8/18
 * Time: 14:49
 */

namespace app\api\service;

use app\api\controller\Base;
use app\api\model\Cancel as CancelModel;
use app\api\model\Product as ProductModel;
use app\common\enum\ProductEnum;
use think\Request;

class CancelService extends Base
{

    //核销记录
    public function cancelList()
    {
        return (new ProductModel())->where('is_show', '=', ProductEnum::IS_SHOW)->field('id,name,image')->select();
    }

    //核销记录详情
    public function cancelDetailsList($userId)
    {
        $request = Request::instance()->get();
        parent::validate($request, 'CancelValidate');
        $where['product_id'] = $request['product_id']; //商品ID
        $where['cancel_id'] = $userId; //当前核销员
        $data = (new CancelModel())->where($where)->select();
        foreach ($data as &$value) {
            $value['admission_time'] = date('Y-m-d H:i:s', $value['admission_time']);
            $value['appearance_time'] = date('Y-m-d H:i:s', $value['appearance_time']);
        }
        unset($value);
        return $data;
    }

}
